package com.gongpingjialoan.adapter.tool;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gongpingjialoan.R;

public class RiskCovrAdapter extends BaseAdapter
{
    
    private LayoutInflater mLayoutInflater;
    
    ViewHolder holder;
    
    private List<Map<String, String>> riskCoverList;
    
    Context context;
    
    public RiskCovrAdapter(Context context)
    {
        this.context = context;
        mLayoutInflater = LayoutInflater.from(context);
    }
    
    public void setData(List<Map<String, String>> riskCoverList)
    {
        this.riskCoverList = riskCoverList;
        notifyDataSetChanged();
    }
    
    @Override
    public int getCount()
    {
        if (riskCoverList == null)
        {
            return 0;
        }
        return riskCoverList.size();
    }
    
    @Override
    public Object getItem(int position)
    {
        return null;
    }
    
    @Override
    public long getItemId(int position)
    {
        return 0;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        if (convertView == null)
        {
            convertView = mLayoutInflater.inflate(R.layout.list_risk_cover_record, null);
            holder = new ViewHolder();
            holder.infoView = (TextView)convertView.findViewById(R.id.info);
            holder.timeView = (TextView)convertView.findViewById(R.id.time);
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder)convertView.getTag();
        }
        Map<String, String> riskCoverMap = riskCoverList.get(position);
        // StringBuffer sb = new StringBuffer();
        // sb.append(riskCoverMap.get("StartDate")).append("·").append(riskCoverMap.get("EndDate")).append("·").append(riskCoverMap.get("RiskType"));
        
        holder.timeView.setText(riskCoverMap.get("StartDate") + " 至 " + riskCoverMap.get("EndDate"));
        holder.infoView.setText(riskCoverMap.get("RiskType"));
        return convertView;
    }
    
    class ViewHolder
    {
        TextView infoView;
        
        TextView timeView;
    }
}